﻿using Blog.Models.Entitys;
using Blog.Models.ReqModels;
using Blog.Models.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Blog.Service.Base
{
    public interface IBaseService<TEntity> where TEntity : BaseEntity
    {
        /// <summary>
        /// 根据id查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns>查询到的实体</returns>
        Task<TEntity> Query(int id);
        /// <summary>
        /// 根据多个id查询
        /// </summary>
        /// <param name="ids">id集合</param>
        /// <returns>查询到的多个实体集合</returns>
        Task<IList<TEntity>> Query(IList<int> ids);
        /// <summary>
        /// 查询全部内容
        /// </summary>
        /// <returns>返回所有内容</returns>
        Task<IList<TEntity>> Query();
        /// <summary>
        /// 根据表达式查询
        /// </summary>
        /// <param name="expression">表达式目录树</param>
        /// <returns>查询到的结果集</returns>
        Task<IList<TEntity>> Query(Expression<Func<TEntity, bool>> expression);
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">分页查询对象</param>
        /// <returns></returns>
        Task<PageList<TEntity>> QueryPage<TQuery>(TQuery query) where TQuery : BaseQuery;
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity">修改实体</param>
        /// <returns>修改后的实体</returns>
        Task<TEntity> Update(TEntity entity);
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="entities">需要修改的实体集合</param>
        /// <returns>修改后的实体集合</returns>
        Task<IList<TEntity>> BatchUpdate(IList<TEntity> entities);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">id主键</param>
        /// <returns>删除的受影响行数</returns>
        Task<int> Delete(int id);
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids">id集合</param>
        /// <returns>受影响行数</returns>
        Task<int> BatchDelete(IList<int> ids);
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity">添加的实体</param>
        /// <returns>添加后的实体</returns>
        Task<TEntity> Insert(TEntity entity);
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="entities">需要添加的实体集合</param>
        /// <returns>添加后的实体集合</returns>
        Task<IList<TEntity>> BatchInsert(IList<TEntity> entities);
    }
}
